/**
 * Created by Administrator on 2017/6/7.
 */
$(document).ready(function(){

    //判断是否登录start
    function getcookie(objname){//获取指定名称的cookie的值
        var arrstr = document.cookie.split("; ");
        for(var i = 0;i < arrstr.length;i ++){
            var temp = arrstr[i].split("=");
            if(temp[0] == objname&&temp[1]=="yes"){
                console.log("用户已经登录")
                getUserContent();
            }else if(temp[0] == objname&&temp[1]!="yes"){
                console.log("已注销")
            }
        }
    }
    getcookie("islogin");
    //判断是否登录end
    //登录后将用户信息输出到页面start
    function  getUserContent(){
        getAllUser=$.ajax({url:"/user/1",async:false});
       var user =getAllUser.responseJSON.data[0];
        $("#username").html(user.userName);
        console.log(user.userName+user.age)
    }
    //登录后将用户信息输出到页面end


    var posts=$.ajax({url:"/post/allPost",async:false}).responseJSON.data;
    console.log(posts[0].posttitle)


    $("#getAllUser").click(function(){
        $.ajax({url:"/user/1",async:false});
        console.log(document.cookie)
    })

})

